#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <string.h>
int main ()
{
  int pipe_own[2];
  int pipe_ow2[2];
  int size;
  char temp[100];
  pid_t pid;
  memset(temp,'\0',strlen(temp));
  if(pipe(pipe_own)<0)
  {
    printf("create pipe_own error \n");
    return 1;
  }
  printf("pipe_own %d %d\n",pipe_own[0],pipe_own[1]);
  
  if(pipe(pipe_ow2)<0)
  {
    printf("create pipe_ow2 error \n");
    return 1;
  }
  printf("pipe_ow2 %d %d\n",pipe_ow2[0],pipe_ow2[1]);
  if ((pid=fork())== 0 )  
  {
    close(pipe_own[0]);
    strcpy(temp,"HelloWorld");
    size = write(pipe_own[1],temp,sizeof("HelloWorld"));
    printf("pipe_own[1] write size is %d \n",size);
    sleep(2);
    close(pipe_ow2[1]);
    size = read(pipe_ow2[0],temp,sizeof("kangness"));
    printf("pipe_ow2[0] read size is %d \n",size);
    printf("%s \n",temp);
    
  }
  else if (pid >0)
  {
    char tempp[100];
    memset(tempp,'\0',100);
    close(pipe_ow2[0]);
    strcpy(tempp,"kangness");
    size = write(pipe_ow2[1],tempp,sizeof("kangness"));
    printf("pipe_own[1] write size is %d \n",size);
    sleep(2);
    close(pipe_own[1]);
    size = read(pipe_own[0],tempp,sizeof("HelloWorld"));
    printf("pipe_ow2[0] read size is %d \n",size);
    printf("%s \n",tempp);
    memset(tempp,'\0',100);
    size = read(pipe_own[0],tempp,sizeof("HelloWorld"));
    printf("pipe_ow2[0] read size is %d \n",size);
    printf("%s \n",tempp);
  }
  close(pipe_ow2[0]);
  close(pipe_ow2[1]);
  close(pipe_own[0]);
  close(pipe_own[1]);
    
  return 0;
  
  
}
